package cn.haixiang.org.service.impl;

import cn.haixiang.basice.util.PageList;
import cn.haixiang.org.domain.Employee;
import cn.haixiang.org.mapper.EmployeeMapper;
import cn.haixiang.org.query.EmployeeQuery;
import cn.haixiang.org.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class EmployeeServiceImpl implements IEmployeeService {
    @Autowired
    private EmployeeMapper mapper;

    @Override
    public List<Employee> findAll() {
        return mapper.findAll();
    }

    @Override
    public Employee findById(Long id) {
        return mapper.findById(id);
    }

    @Override
    public void update(Employee department) {
        mapper.update(department);
    }

    @Override
    public void delete(Long id) {
        mapper.delete(id);
    }

    @Override
    public void add(Employee department) {
    mapper.add(department);
    }

    @Override
    public PageList<Employee> queryByPage(EmployeeQuery query) {
        // 查询 条数
        Integer totals = mapper.queryByCount(query);
        if (null == totals || 0 == totals){
            return new PageList<Employee>(0,new ArrayList<>());//前端不想要null值所以要选0条
        }
        // 查询数据
        List<Employee> rows = mapper.queryByPage(query);
        return new PageList<>(totals,rows);
    }

    @Override
    public void batchDelete(List<Long> ids) {
        mapper.batchDelete(ids);

    }
}